#!/bin/bash
# 编译
go build printer.go
go build selpg.go

# 生成输出文件
test_out="./data/test_out.txt"
> $test_out

testcase=1

echo "-TEST ${testcase}:-" >> $test_out
echo "-RUN: ./selpg -s1 -e1 ./data/input.txt" >> $test_out
echo "-GET(Stdout): " >> $test_out
./selpg -s1 -e1 ./data/input.txt >> $test_out
echo  >> $test_out
echo "-----------------------------------------------------------" >> $test_out

let testcase+=1
echo "-TEST ${testcase}:-两行为1页" >> $test_out
echo "-RUN: ./selpg -s1 -e1 -l2 ./data/input.txt" >> $test_out
echo "-GET(Stdout): " >> $test_out
./selpg -s1 -e1 -l2 ./data/input.txt >> $test_out
echo "-----------------------------------------------------------" >> $test_out

let testcase+=1
echo "-TEST ${testcase}:-定界符为\f" >> $test_out
echo "-RUN: ./selpg -s1 -e2 -f ./data/input.txt" >> $test_out
echo "-GET(Stdout): " >> $test_out
./selpg -s1 -e2 -f ./data/input.txt >> $test_out
echo  >> $test_out
echo "-----------------------------------------------------------" >> $test_out

let testcase+=1
echo "-TEST ${testcase}:-" >> $test_out
echo "-RUN: ./selpg -s2 -e3 -l2 < ./data/input.txt" >> $test_out
echo "-GET(Stdout): " >> $test_out
./selpg -s2 -e3 -l2 < ./data/input.txt >> $test_out
echo "-----------------------------------------------------------" >> $test_out

let testcase+=1
echo "-TEST ${testcase}:-" >> $test_out
echo "-RUN: cat ./data/input.txt | ./selpg -s4 -e5 -f" >> $test_out
echo "-GET(Stdout): " >> $test_out
cat ./data/input.txt | ./selpg -s4 -e5 -f >> $test_out
echo  >> $test_out
echo "-----------------------------------------------------------" >> $test_out

let testcase+=1
echo "-TEST ${testcase}:-输出重定向" >> $test_out
echo "-RUN: ./selpg -s1 -e1 ./data/input.txt > ./data/output.txt" >> $test_out
echo "-GET(./data/output.txt): " >> $test_out
./selpg -s1 -e1 ./data/input.txt > ./data/output.txt && cat ./data/output.txt >> $test_out
echo  >> $test_out
echo "-----------------------------------------------------------" >> $test_out

let testcase+=1
echo "-TEST ${testcase}:-错误重定向" >> $test_out
echo "-RUN: ./selpg -s1 -e2 ./data/input.txt 2> ./data/error.txt" >> $test_out
echo "-GET(Stdout): " >> $test_out
./selpg -s1 -e2 ./data/input.txt 2> ./data/error.txt >> $test_out 
echo  >> $test_out
echo "-GET(./data/error.txt): " >> $test_out
cat ./data/error.txt >> $test_out
echo "-----------------------------------------------------------" >> $test_out

let testcase+=1
echo "-TEST ${testcase}:-输出和错误重定向" >> $test_out
echo "-RUN: ./selpg -s1 -e2 ./data/input.txt >./data/output.txt 2>./data/error.txt" >> $test_out
./selpg -s1 -e2 ./data/input.txt >./data/output.txt 2>./data/error.txt
echo "-GET(./data/output.txt): " >> $test_out
cat ./data/output.txt >> $test_out
echo  >> $test_out
echo "-GET(./data/error.txt): " >> $test_out
cat ./data/error.txt >> $test_out
echo "-----------------------------------------------------------" >> $test_out

let testcase+=1
echo "-TEST ${testcase}:-错误重定向到/dev/null" >> $test_out
echo "-RUN: ./selpg -s1 -e2 ./data/input.txt >./data/output.txt 2>/dev/null" >> $test_out
./selpg -s1 -e2 ./data/input.txt >./data/output.txt 2>/dev/null
echo "-GET(./data/output.txt): " >> $test_out
cat ./data/output.txt >> $test_out
echo  >> $test_out
echo "-GET(/dev/null): " >> $test_out
cat /dev/null >> $test_out
echo "-----------------------------------------------------------" >> $test_out

let testcase+=1
echo "-TEST ${testcase}:-输出重定向到/dev/null" >> $test_out
echo "-RUN: ./selpg -s1 -e1 ./data/input.txt >/dev/null" >> $test_out
./selpg -s1 -e1 ./data/input.txt >/dev/null
echo "-GET(/dev/null): " >> $test_out
cat /dev/null >> $test_out
echo "-----------------------------------------------------------" >> $test_out


let testcase+=1
echo "-TEST ${testcase}:-" >> $test_out
echo "-RUN: ./selpg -s4 -e5 -f ./data/input.txt | grep 4" >> $test_out
echo "-GET(Stdout): " >> $test_out
./selpg -s4 -e5 -f ./data/input.txt | grep 4 >> $test_out
echo "-----------------------------------------------------------" >> $test_out

let testcase+=1
echo "-TEST ${testcase}:-" >> $test_out
echo "-RUN: ./selpg -s4 -e7 -f ./data/input.txt 2>./data/error.txt | grep 6" >> $test_out
echo "-GET(Stdout): " >> $test_out
./selpg -s4 -e7 -f ./data/input.txt 2>./data/error.txt | grep 6 >> $test_out
echo "-GET(./data/error.txt): " >> $test_out
cat ./data/error.txt >> $test_out
echo "-----------------------------------------------------------" >> $test_out

let testcase+=1
echo "-TEST ${testcase}:-打印机" >> $test_out
echo "-RUN: ./selpg -s2 -e4 -f -dprinter ./data/input.txt" >> $test_out
./selpg -s2 -e4 -f -dprinter ./data/input.txt
echo "-GET(./data/printer.txt): " >> $test_out
cat ./data/printer.txt >> $test_out
echo  >> $test_out
echo "-----------------------------------------------------------" >> $test_out


# 方便你查看所有的test
less $test_out